//*****************************************************************
// OperatorThread.h
//
//  Created on: Jan 21, 2012
//      Author: Christopher Wood
//              Robert Livosi
//
//  $Id: OperatorThread.h 30 2012-01-29 21:29:24Z caw4567 $
//*****************************************************************

#ifndef OPERATORTHREAD_H_
#define OPERATORTHREAD_H_

#include "Project2.h"
#include "Controller.h"
#include "IOThreadGroup.h"

// Resolve forward declaration
class Controller;
class IOThreadGroup;

/**
 * This class is responsible for handling the user input that controls
 * the main analog I/O thread group and the PID transform function.
 */
class OperatorThread
{
public:
	/**
	 * Default constructor that sets the transform and I/O threads.
	 *
	 * @param tThread - the desired transform thread to control.
	 * @param ioGroup - the I/O group that is managed.
	 */
	OperatorThread(Controller* controller, IOThreadGroup* ioGroup);

	/**
	 * Default destructor.
	 */
	virtual ~OperatorThread();

	/**
	 * Retrieve the controller object being managed by this thread.
	 *
	 * @return a pointer to the controller thread object
	 */
	Controller* getController();

	/**
	 * Retrieve a pointer to the IOThreadGroup object being controlled by this thread.
	 *
	 * @param a pointer to the IOThreadGroup object.
	 */
	IOThreadGroup* getIOThreadGroup();

	/**
	 * Determine if this thread is done controlling the others.
	 *
	 * @return true if done, false otherwise.
	 */
	bool isComplete();

	/**
	 * Set the control completion status.
	 *
	 * @param b - new boolean value.
	 */
	void setComplete(bool b);

	/**
	 * Start the thread.
	 */
	void run();

protected:
	// Pointer to the transform object this thread controls.
	Controller* controller;

	// Pointer to the input/output thread group this thread controls.
	IOThreadGroup* ioGroup;

	// Boolean flag indicating the status of the thread.
	volatile bool threadAlive;

	// Boolean flag indicating thread control complete.
	volatile bool controlComplete;

	// The user input thread ID
	pthread_t threadID;
};

#endif /* OPERATORTHREAD_H_ */
